<script>
  function round_decimals(original_number,decimals)
  {
    var result1=original_number*Math.pow(10,decimals);
    var result2=Math.round(result1);
    var result3=result2/Math.pow(10,decimals);
    return pad_with_zeros(result3,decimals);
  }

  function pad_with_zeros(rounded_value,decimal_places)
  {
    var value_string=rounded_value.toString();
    var decimal_location=value_string.indexOf(".");
    if(decimal_location == -1)
    {
      decimal_part_length=0;
      value_string+=decimal_places >0 ? ".": "";
    }else
    {
      decimal_part_length=value_string.length - decimal_location - 1;
    }

    var pad_total=decimal_places - decimal_part_length;

    for(var counter=1;counter <= pad_total;counter++)
    {
      value_string+="0";
    }
    return value_string;
  }

  var my_number=123;
  document.write(round_decimals(my_number,5));
</script>
